package com.atguigu.mall.tripartite.controller;

import cn.hutool.core.util.StrUtil;
import com.atguigu.common.utils.R;
import com.atguigu.mall.tripartite.util.OSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
@RestController
@RequestMapping("tripartite/oss")
@Slf4j
public class OssController {


    @PostMapping(value = "/upload/image")
    private R upLoadImage(@RequestParam("file") MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String imgName =  StrUtil.uuid() +"_"+fileName;
        FileInputStream inputStream = (FileInputStream) file.getInputStream();
        String path = OSSUtil.uploadQNImg(inputStream, imgName);
        log.info("七牛云返回的图片链接:" + path);
        return  R.ok().put("path", path);
    }
}
